<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/operatehistory.jsp"%>
<%
    Integer uid = token.getUid();
    List<Map> depts = QBuilder.db("basedb").select("distinct new map (h.id as id, h.name as dept_name,h.descr as hospital_name, h.hospital as dept_id, h.jsonString as json, 1199 as dept_id, h.parent as parent)").from("OperateHistory as o, Hospital as h").where(new Where("o.hospital=", hospital).and("o.status=", STATUS_ENABLE).and("o.uid=", uid).and("o.operate=", ATTENTION).and("o.category=", DEPT_CATEGORY).and("h.id=o.oid").and("h.status=", STATUS_ENABLE)).query().getResultObj();
	for (Map map:depts) {
		Map jsonMap = JSONUtil.fromJson(map.remove("json") + "", new TypeReference<Map>(){});
		if (isEmpty(jsonMap))
			jsonMap = new HashMap();
		map.put("avatar", Tools.getDesc(jsonMap.get("avatar"), "http://cdn-img.easyicon.net/png/11907/1190716.gif"));
	}
	List<Map> experts = QBuilder.db("basedb").select("distinct new map (u.id as id, u.name as name, u.avatar as avatar, u.title as title, h.name as dept_name,h.descr as hospital_name, h.hospital as dept_id, u.gender as gender)").from("OperateHistory as o, Hospital as h, User as u").where(new Where("o.hospital=", hospital).and("o.status=", STATUS_ENABLE).and("o.uid=", uid).and("o.operate=", ATTENTION).and("o.category=", SECTION_DOCTOR).and("u.id=o.oid").and("h.status=", STATUS_ENABLE).and("h.hospital=u.hospital").and("u.type=", USER_EMPLOYEE)).query().getResultObj();
	for (Map expert:experts) {
		if (expert.get("avatar") != null)            
			continue;
		expert.put("avatar", Tools.getInt(expert.get("gender") + "") == 0?EMPLOYEE_AVATAR_FM:EMPLOYEE_AVATAR_M);
	}
	Map<String, Object> data = new HashMap<String, Object>();
	data.put("depts", depts);
	data.put("experts", experts);
    msg.put("data", data);
    Tools.encryptPrint(out, msg);
%>
